<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="姓名" prop="Name">
                <el-input v-model="queryParams.Name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>


            <el-form-item label="就诊卡号" prop=" medicalCardNumber">
                <el-input v-model="queryParams.medicalCardNumber" placeholder="请输入就诊卡号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['manage:archives:basicInfoDe']">修改</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="ID" align="center" prop="userId" />
            <el-table-column label="姓名" align="center" prop="Name" />
            <el-table-column label="手机号" align="center" prop="phoneNumber" />
            <el-table-column label="就诊卡号" align="center" prop=" medicalCardNumber" />
            <el-table-column label="状态" align="center" prop="status">
                <el-button size="mini" type="success">正常</el-button>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:user:edit']">基础检查信息</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
    </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser, } from "@/api/system/user";

export default {
    name: "User",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 角色信息表格数据
            userList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                Name: null,
                phonenumber: null,
                userId: null,
                medicalCardNumber: null,
                status: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                Name: [
                    { required: true, message: "姓名不能为空", trigger: "blur" }
                ],
                medicalCardNumber: [
                    { required: true, message: "就诊卡号能为空", trigger: "blur" }
                ],

            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询角色信息列表 */
        getList() {
            this.loading = true;
            listUser(this.queryParams).then(response => {
                this.userList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                Name: null,
                phonenumber: null,
                userId: null,
                medicalCardNumber: null,
                status: null,
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.userId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 跳转到详细信息 */
        handleUpdate(row) {
            this.reset();
            const userId = row.userId || this.ids;
            const params = { userId: row.userId };
            this.$tab.openPage(
                "基础检查信息",
                "/manage/archives/basicInfo/basicInfoDe",
                params
            );
        },
    }
};
</script>
